#pragma once

#include "..\\headers.default.h"
#include "..\\headers.cv.h"
#include "..\\headers.classification.h"
#include "..\\headers.obj.detect.h"

#include "voc.pascal.FileNameManager.h"
#include "voc.pascal.ClassInfo.h"
#include "voc.pascal.Data.h"

namespace voc_pascal
{
	class CAnnotationInfo
	{
	public:
		CClassInfo ClassInfo;
		string strAspect;
		string strIsTruncated;
		string strIsDifficult;

	public:
		void SetAnnotationInfo(
			CClassSet* pClassSet, const string& ClassName,
			const string& strAspect,
			const string& strIsTruncated,
			const string& strIsDifficult
			);
	};

	class CGroundTruthItem : public CAnnotationInfo
	{
	public:
		CRectBox<int> TightBox;
		CRectBox<int> LooseBox;

	public:
		bool InputFromStream(istream& inStream, CClassSet* pClassSet);
		bool InputFromStream(istream& inStream, CClassSet* pClassSet, string& strTitle);
		void OutputToStream(ostream& outStream, const string& strTitle = "*") const;
	};

	class CTargetConfig : public CAnnotationInfo
	{
	public:
		bool Check(const CAnnotationInfo* pAnnotationInfo) const;
	};

	class CAnnotationFileConfig
	{
	public:
		string sntW;
		string sntH;
		string sntObject;
		string sntClassName;
		string sntAspect;
		string sntIsTruncated;
		string sntIsDifficult;
		string sntBox;
		string sntXMin;
		string sntXMax;
		string sntYMin;
		string sntYMax;
	};

	class CImageGtInfo
	{
	public:
		static CAnnotationFileConfig AnnotationFileConfig;
	public:
		int W,H;
		string strImageTitle;
		CSimpleTypeArray<CGroundTruthItem> GtItemList;
		bool fHasInstances;
		
	public:
		void myInit_2006(const string& strFN_TXT_Annotation, CClassSet* pClassSet);
		void myInit_2007(const string& strFN_XML_Annotation, CClassSet* pClassSet);
		bool InputFromStream(istream& inStream, CClassSet* pClassSet);
		void OutputToStream(ostream& outStream);
	};

	class CImageGtInfoSet
	{
	protected:
		map<string, int> it2index;
	public:
		CSimpleTypeArray<CImageGtInfo> igtList;
	public:
		bool InputFromFile(const string& strFN_ImageGtInfoSet, CClassSet* pClassSet);
		void OutputToFile(const string& strFN_ImageGtInfoSet);
		void InitMapping();
		int GetImageGtInfo(CImageGtInfo& DstIGT, const string& strImageTitle) const;
		const CImageGtInfo& GetImageGtInfo(const string& strImageTitle) const;
	};

	class CBoxExample
	{
	public:
		CRectBox<int> Box;
		int ImageIndex;
		bool fIsPos;
		double InitialWeight;
	public:
		bool InputFromStream(istream& inStream, const CFileNameList& FileNameList);
		void OutputToStream(ostream& outStream, const CFileNameList& FileNameList) const;
	};

	class CDataSet_VocPascal_ByImage : public CDataSetForBinaryClassification
	{
	protected:
		CFileNameList* _pFileNameList;
		CSimpleTypeArray<CImageBoxFeatureExtractor*> _IBFE_Pool;
		CCacheManager* _pCacheManager;

	public:
		CSimpleTypeArray<CBoxExample> NodeList;

	protected:
		void myRelease();
	public:
		CDataSet_VocPascal_ByImage();
		~CDataSet_VocPascal_ByImage();

		void InitFeatureSettings(int ImagePoolSize, CFileNameList* pFileNameList);
		void InputNodeListFromFile(const string& strFN_NodeList, const CFileNameList& FileNameList);
		void OutputNodeListToFile(const string& strFN_NodeList, const CFileNameList& FileNameList) const;
		void OutputNodeListToStream(ostream& outStream, const CFileNameList& FileNameList) const;
	public:
		virtual int GetNodeAmount();
		virtual double GetNodeInitialWeight(int NodeIndex);
		virtual int GetFeatureDim();
		virtual double GetNodeFeature(int NodeIndex, int FeatureIndex);
		virtual int GetNodeFlag(int NodeIndex);
	};
};

